unit SmallStruct.Database;

interface

uses Classes,
  DB,
  SmallStruct.Core,
  SmallStruct.Tools,
  SmallStruct.Configuration;

const
  SS_DATABASE_CONNECTION_FACTORY_NAME: string = 'DATABASE_CONNECTION_FACTORY';
  SS_ADO_DATABASE_DRIVER: string = 'ADO_DATABASE_DRIVER';
  SS_DBX_DATABASE_DRIVER: string = 'DBX_DATABASE_DRIVER';

  DT_INTEGER = 'INTEGER';
  DT_NUMERIC = 'NUMERIC(16, 4)';
  DT_DATE = 'DATE';
  DT_VARCHAR8 = 'VARCHAR(8)';
  DT_VARCHAR32 = 'VARCHAR(32)';
  DT_VARCHAR128 = 'VARCHAR(128';

type
  ISSDatabaseDriverContext = interface(ISSObjectContext)
    ['{F7C360ED-7668-49D7-8E30-E2F6569DAB05}']
  end;

  ISSDataSet = interface(ISSObject)
    ['{5B965A89-9434-478F-803A-5CC624038FA4}']
    function GetBooleanValue(const AFieldName: string): Boolean;
    function GetCount: Integer;
    function GetCurrencyValue(const AFieldName: string): Currency;
    function GetDataSet: TDataSet;
    function GetDateTimeValue(const AFieldName: string): TDateTime;
    function GetDoubleValue(const AFieldName: string): Double;
    function GetFieldCount: Integer;
    function GetFieldName(const AIndex: Integer): string;
    function GetIntegerValue(const AFieldName: string): Integer;
    function GetData: ISSRecord; overload;
    function GetData(ABookmark: TStringList): ISSObjectContainer; overload;
    function GetStringValue(const AFieldName: string): string;
    function GetValue(const AFieldName: string): Variant;
    function GetValueAverage(const AFieldName: string): Variant;
    function GetValueSum(const AFieldName: string): Variant;
    function GetValueMax(const AFieldName: string): Variant;
    function GetValueMin(const AFieldName: string): Variant;
    function IsBof: Boolean;
    function IsEof: Boolean;
    procedure SetFilter(const AFilter: string);
    procedure SetIndex(const AFieldName: string);
    procedure Next;
    procedure Prior;
    procedure First;
    procedure Last;
  end;

  ISSDataSetModifiable = interface(ISSDataSet)
    ['{5B2CD88A-AE04-4C7B-A030-DA19321E73E1}']
    procedure Append;
    procedure Delete;
    procedure SetValue(const AFieldName: string; Value: Variant);
    procedure SetNull(const AFieldName: string);
    procedure Save;
  end;

  ISSDatabaseDriver = interface(ISSRuntimeObject)
    ['{B791641C-6698-4961-8BC8-1AB4CC3DDE5B}']
    function ExecuteProcedure(const ProcedureName: string; Parameters: Variant): Integer;
    function ExecuteSQL(const SQL: string): Integer;
    function Query(const SQL: string): ISSDataSet; overload;
    function QueryByModified(const SQL: string): ISSDataSetModifiable; overload;
    function UploadBlobField(const EntityName, KeyFieldName, BlobFieldName: string; Key: Integer; Buffer: TStream): Integer;
    function DownloadBlobField(const EntityName, KeyFieldName, BlobFieldName: string; Key: Integer; Buffer: TStream): Integer;
    procedure CommitTransaction;
    procedure Conntect;
    procedure Deconnect;
    procedure GetTableNames(ATableNames: TStringList);
    procedure GetFieldNames(const ATableName: string; AFieldNames: TStringList);
    procedure RollbackTransaction;
    procedure StartTransaction;
    function AppendTable(const TableName, KeyFieldName: string): Boolean;
    function DeleteTable(const TableName: string): Boolean;
    function AppendField(const TableName, FieldName, DataType: string): Boolean;
    function DeleteField(const TableName, FieldName: string): Boolean;
    function FindTable(const TableName: string): Boolean;
    function FindField(const TableName, FieldName: string): Boolean;
  end;

  ISSDatabaseConnectionFactory = interface(ISSRuntimeObject)
    ['{59582D20-F005-48F0-B664-F3CD170F33C1}']
    function CreateDatabaseConnection(DatabaseConnectionConfiguration: ISSDatabaseConnectionConfiguration): ISSDatabaseDriver;
    function GetDatabaseConnection(const ADatabaseConnectionName: string): ISSDatabaseDriver;
  end;

implementation

end.
